package com.pets.controller;

import com.pets.qo.AnimalAddQO;
import com.pets.qo.KnowledgeAddQO;
import com.pets.service.AnimalService;
import com.pets.service.KnowledgeService;
import com.pets.util.AjaxLogicBean;
import com.pets.util.PageData;
import com.pets.util.Result;
import com.pets.vo.AnimalVO;
import com.pets.vo.KnowledgeDisVO;
import com.pets.vo.KnowledgesByPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value="/animal")
public class AnimalController {
    @Autowired
    private AnimalService animalService;

    /**
     * 分页显示
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping(value="/selectAnimalsByPage")
    public ModelAndView selectAnimalsByPage(int page,int pageSize){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/user/adopt");
        PageData<AnimalVO> animals = animalService.selectAnimalsByPage(page,pageSize);
        modelAndView.addObject("pd",animals);
        return modelAndView;
    }


    @RequestMapping(value="/selectAnimalByAId")
    public ModelAndView selectAnimalByAId(int aId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/user/animal_information");
        AnimalVO animal= animalService.show(aId);
        modelAndView.addObject("ashow",animal);
        return modelAndView;
    }


    @ResponseBody
    @RequestMapping(value = "/animalAdd", method = RequestMethod.POST)
    public Result AnimalAdd(AnimalAddQO animalAddQO) {
        Result result = animalService.AnimalAdd(animalAddQO);
        return result;
    }
}
